package com.dalin.platform.glb.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.platform.autocode.condition.GlbDicItemRepositoryCondition;
import com.dalin.platform.pub.PlatContext;
/*****************************************************************************
 * @content: 字典表主表类信息                                                                                                                 *
 * @author : 那建林                                                                                                                                 *
 * @remark : 修改命名规则                                                                                                                      *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-18                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="GLB_DIC_TYPE_REPOSITORY")
public class GlbDicTypeRepositoryEntity extends BaseObject {
	private Long typeId; // TYPE_ID,16,0
    private String typeCode; // TYPE_CODE,64,0
    private String typeDescription; // TYPE_DESCRIPTION,256,0


    @Id
    @Column(name="TYPE_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "GLB_DIC_TYPE_REPOSITORY",
        allocationSize=1
    )
    public Long getTypeId() {
        return typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    @Column(name="TYPE_CODE")
    public String getTypeCode() {
        return typeCode;
    }

    public void setTypeCode(String typeCode) {
        this.typeCode = typeCode;
    }

    @Column(name="TYPE_DESCRIPTION")
    public String getTypeDescription() {
        return typeDescription;
    }

    public void setTypeDescription(String typeDescription) {
        this.typeDescription = typeDescription;
    }

    
    @Transient
    public List<GlbDicItemRepositoryEntity> getGlbDicItemRepositoryEntitys() throws Exception {
    	GlbDicItemRepositoryCondition cond = new GlbDicItemRepositoryCondition();
    	cond.setTypeId(this.getTypeId());
		return PlatContext.getDao().queryObjsToPages(cond.prepareParams()
					.getPreparedPageQuery());
	}

    @Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (typeId == null ? 0 : typeId.hashCode());
        njlrst = 31 * njlrst + (typeCode == null ? 0 : typeCode.hashCode());
        njlrst = 31 * njlrst + (typeDescription == null ? 0 : typeDescription.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof GlbDicTypeRepositoryEntity)) return false;
        final GlbDicTypeRepositoryEntity other = (GlbDicTypeRepositoryEntity) o;
        if (typeId == null) {
            if (other.typeId != null) return false;
        } else if (!typeId.equals(other.typeId)) {
            return false;
        }
        if (typeCode == null) {
            if (other.typeCode != null) return false;
        } else if (!typeCode.equals(other.typeCode)) {
            return false;
        }
        if (typeDescription == null) {
            if (other.typeDescription != null) return false;
        } else if (!typeDescription.equals(other.typeDescription)) {
            return false;
        }
        return true;
    }
}
